<?php

namespace app\api\Service;

use app\common\library\Auth;
use app\common\model\Area;
use think\Config;

class IndexService
{
    // 获取轮播图
    public static function getBanner()
    {
        $list = \app\admin\model\Banner::where(['type'=>1,'status'=>'normal'])
            ->order('weigh desc')->field('id,image,content')->select();
        return ['code' =>1,'msg'=>'查询成功','data'=>$list];
    }

    // 获取服务分类
    public static function getServiceType()
    {
        $list = \app\admin\model\ServiceType::where(['status'=>'normal'])
            ->order('weigh desc')->field('id,image,name')->select();
        return ['code' =>1,'msg'=>'查询成功','data'=>$list];
    }

    // 获取标语
    public static function getSlogan()
    {
        $slogan = Config::get("site.home_slogan");
        return ['code' =>1,'msg'=>'查询成功','data'=>$slogan];
    }

    // 运营区域
    public static function getCitySelectpage()
    {

        $city_ids = Area::where(['is_operate'=>1])->column('pid');
        $province_ids = Area::where(['id'=>['in',$city_ids]])->column('pid');

        $list = Area::where(['id'=>['in',$province_ids]])->field('id,name,lng,lat')->select();
        foreach($list as &$item){
            $city = Area::where(['id'=>['in',$city_ids],'pid'=>$item['id']])->field('id,name,lng,lat')->select();

            foreach($city as &$row){
                $area = Area::where(['pid'=>$row['id'],'is_operate'=>1])->field('id,name,lng,lat')->select();
                $row['children'] = $area;
            }
            $item['children'] = $city;

        }

        return ['code'=>1,'msg'=>'查询成功','data'=>['list'=>$list]];
    }

    // 积分转换比例
    public static function getConversionRatio()
    {
        $conversion_ratio = Config::get("site.conversion_ratio");
        return ['code' =>1,'msg'=>'查询成功','data'=>$conversion_ratio];
    }

    // 城市列表
    public static function getArea($data)
    {
        $level = isset($data['level']) ? $data['level'] : 1;
        $pid = isset($data['pid']) ? $data['pid'] : 0;

        $list = Area::where(['pid'=>$pid,'level'=>$level])->field('id,name')->select();
        return ['code'=>1,'msg'=>'操作成功','data'=>$list];
    }
    
    // 400
    public static function phoneCall400()
    {
        $phone = Config::get("site.400phone");
        return ['code' =>1,'msg'=>'查询成功','data'=>$phone];
    }
    
    // 企业微信你客服
    public static function enterpriseWeChatCustomerService()
    {
        $list = ['link'=>"https://work.weixin.qq.com/kfid/kfc9d989ce99dc2f509",'uid'=>"wwaeb7307f6648d52d"];
        return ['code' =>1,'msg'=>'查询成功','data'=>$list];
    }
}
